//
//  FindDetailHostTableViewCell.m
//  XWZ_News_Work
//
//  Created by penngshi on 16/1/13.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "FindDetailHostTableViewCell.h"
//@property (nonatomic , strong) UIImageView *headerView;
//@property (nonatomic , strong) UILabel *nameLabel;
//@property (nonatomic , strong) UILabel *cententLabel;
//@property (nonatomic , strong) FinfModel *findeModel;
@implementation FindDetailHostTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}
+ (CGFloat)heightWithStr:(NSString *)str
{
    CGRect frame = [str boundingRectWithSize:CGSizeMake(300, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:18.0] forKey:NSFontAttributeName]context:nil];
    
    
    return frame.size.height;
}
- (void)layoutSubviews

{
    [super layoutSubviews];
    
    self.backGroub.frame = self.frame;
    self.userHeaderView.frame = CGRectMake(10, 10, 30, 30);
    
    self.userNameLabel.frame = CGRectMake(self.userHeaderView.frame.size.width + self.userHeaderView.frame.origin.x + 5, self.userHeaderView.frame.origin.y + 5, 300, 20);
    self.userCententLabel.frame = CGRectMake(self.userNameLabel.frame.origin.x, self.userNameLabel.frame.origin.y + self.userNameLabel.frame.size.height + 5 , 300, 50);
    
    CGFloat height = [[self class] heightWithStr:self.userCententLabel.text];
    //    先保存label的坐标及宽度信息
    CGRect frameL = self.userCententLabel.frame;
    frameL.size.height = height ;
    self.userCententLabel.frame = frameL;
    
    
    self.userLabel .frame = CGRectMake(0, self.userCententLabel.frame.size.height + self.userCententLabel.frame.origin.y + 30, SCREEN_WIDTH, 0.2);

    
    
    self.answerHeaderView.frame = CGRectMake(self.userHeaderView.frame.origin.x , self.userLabel.frame.origin.y + 20, 30, 30);
    self.answerHeaderView.layer.masksToBounds = YES;//裁掉边界
    self.answerHeaderView.layer.cornerRadius = 15;//设置半径
    
    self.answerNameLabel.frame = CGRectMake(self.answerHeaderView.frame.size.width + self.answerHeaderView.frame.origin.x + 5, self.answerHeaderView.frame.origin.y, 200, 20);
    
    self.answerCententLabel.frame = CGRectMake(self.answerNameLabel.frame.origin.x, self.answerNameLabel.frame.origin.y + self.answerNameLabel.frame.size.height, 300, 50);
    CGFloat height1 = [[self class] heightWithStr:self.answerCententLabel.text];
    //    先保存label的坐标及宽度信息
    CGRect frameL1 = self.answerCententLabel.frame;
    frameL1.size.height = height1 ;
    self.answerCententLabel.frame = frameL1;
    
    self.bigButton.frame = CGRectMake( self.answerCententLabel.frame.origin.x + self.answerCententLabel.frame.size.width / 2 - 50, self.answerCententLabel.frame.origin.y + self.answerCententLabel.frame.size.height  + 20, 50, 10);
    
    self.answerLabel.frame = CGRectMake(0, self.bigButton.frame.size.height + self.bigButton.frame.origin.y + 40, SCREEN_WIDTH, 0.2);
    
    
    self.timeLabel .frame = CGRectMake(self.answerCententLabel.frame.origin.x,  self.answerLabel.frame.origin.y + 30,110 , 30);
    self.replyCountImageV.frame = CGRectMake(self.timeLabel.frame.origin.x + self.timeLabel.frame.size.width + 50, self.timeLabel.frame.origin.y, 20, 20);
    self.replyCountLabel.frame = CGRectMake(self.replyCountImageV.frame.size.width + self.replyCountImageV.frame.origin.x + 5, self.timeLabel.frame.origin.y, 50, 20);
    self.supportCountImageV.frame = CGRectMake(self.replyCountLabel.frame.size.width + self.replyCountLabel.frame.origin.x + 30, self.timeLabel.frame.origin.y, 20, 20);
    self.supportCountLabel.frame = CGRectMake(self.supportCountImageV.frame.size.width + self.supportCountImageV.frame.origin.x + 5, self.timeLabel.frame.origin.y, 50, 20);
    
    self.replyCountLabel.textColor = [UIColor grayColor];
    self.supportCountLabel.textColor = [UIColor grayColor];
}
- (void)createSubView
{

    
    
    self.userHeaderView = [[UIImageView alloc]init];
    self.userHeaderView.layer.masksToBounds = YES;//裁掉边界
    self.userHeaderView.layer.cornerRadius = 15;//设置半径
    [self.contentView addSubview:self.userHeaderView];
    
    
    self.userNameLabel = [[UILabel alloc]init];
    self.userNameLabel.textColor = [UIColor lightGrayColor];
   
    [self.contentView addSubview:self.userNameLabel];
    
    
    self.userCententLabel = [[UILabel alloc]init];
    self.userCententLabel.textColor = [UIColor darkGrayColor];
     self.userCententLabel.numberOfLines = 0;
    [self.contentView addSubview:self.userCententLabel];
    
    self.userLabel  = [[UILabel alloc]init];
    self.userLabel.backgroundColor = [UIColor blackColor];
    [self.contentView addSubview:self.userLabel];
    
    
    self.answerHeaderView = [[UIImageView alloc]init];
//    self.answerHeaderView.backgroundColor = [UIColor blackColor];
    [self.contentView addSubview:self.answerHeaderView];
    
    self.answerNameLabel = [[UILabel alloc]init];
//    self.answerNameLabel.backgroundColor = [UIColor blackColor];
    [self.contentView addSubview:self.answerNameLabel];


    self.answerCententLabel = [[UILabel alloc]init];
//    self.answerCententLabel.backgroundColor = [UIColor redColor];
    self.answerCententLabel.numberOfLines = 0;
    [self.contentView addSubview:self.answerCententLabel];
    
    
    
    self.answerLabel  = [[UILabel alloc]init];
    self.answerLabel.backgroundColor = [UIColor blackColor];
    [self.contentView addSubview:self.answerLabel];
    
    
    UIImage *rightImage =  [UIImage imageNamed:@"iconfont-xialaanniu"];
    //    图片渲染模式
    rightImage = [rightImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *rightImage1 =  [UIImage imageNamed:@"shangla (2)"];
    //    图片渲染模式
    rightImage1 = [rightImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.bigButton = [UIButton buttonWithType:UIButtonTypeCustom];

    //    self.bigButton.backgroundColor = [UIColor redColor];
    [self.bigButton setImage:rightImage forState:UIControlStateNormal];
    [self.bigButton setImage:rightImage1 forState:UIControlStateSelected];
//    [self.bigButton addTarget:self action:@selector(listButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    self.bigButton.backgroundColor = [UIColor blackColor];
//    [self.contentView addSubview:self.bigButton];
    
    
    self.timeLabel = [[UILabel alloc]init];
//    self.timeLabel.backgroundColor = [UIColor blackColor];
    [self.contentView addSubview:self.timeLabel];
    
    
    self.replyCountImageV  = [[UIImageView alloc]init];
//    self.replyCountImageV.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.replyCountImageV];
    
    
    
    self.replyCountLabel = [[UILabel alloc]init];
//    self.replyCountLabel.backgroundColor = [UIColor blueColor];
    [self.contentView addSubview:self.replyCountLabel];
    
    
    self.supportCountImageV = [[UIImageView alloc]init];
//    self.supportCountImageV.backgroundColor = [UIColor purpleColor];
    [self.contentView addSubview:self.supportCountImageV];
    
    
    self.supportCountLabel = [[UILabel alloc]init];
//     self.supportCountLabel.backgroundColor = [UIColor grayColor];
    [self.contentView addSubview:self.supportCountLabel];
}
- (void)listButtonAction:(UIButton  *)sender
{
    if (sender.selected == NO) {
        
        CGFloat height = [[self class] heightWithStr:self.answerCententLabel.text];
        //    先保存label的坐标及宽度信息
        CGRect frameL = self.answerCententLabel.frame;
        frameL.size.height = height ;
        self.answerCententLabel.frame = frameL;
        self.answerCententLabel.numberOfLines = 0;
//        [self.delegate TrunCellHeight];
        self.bigButton.frame = CGRectMake( self.answerCententLabel.frame.origin.x + self.answerCententLabel.frame.size.width / 2 - 50, self.answerCententLabel.frame.origin.y + self.answerCententLabel.frame.size.height , 50, 10);
        
    } else
    {
        self.answerCententLabel.frame = CGRectMake(self.answerNameLabel.frame.origin.x, self.answerNameLabel.frame.origin.y + self.answerNameLabel.frame.size.height, 300, 130);
        self.answerCententLabel.numberOfLines = 5;
        self.bigButton.frame = CGRectMake( self.answerCententLabel.frame.origin.x + self.answerCententLabel.frame.size.width / 2 - 50, self.answerCententLabel.frame.origin.y + self.answerCententLabel.frame.size.height , 50, 10);
//        [self.delegate TrunCellHeight];
    }
    
    sender.selected =! sender.selected;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
